<?php

class Admin extends Admin_Controller {

	public function main()
	{

		$this->load->view('main',$this->_service);
	}

	public function test()
	{

		$this->load->view('test',$this->_service);
	}

	public function get_client_users(){
		$site_id = $_SESSION['service']->site_id;
		$token = $_SESSION['service']->token;
  		$list = $this->db->where("site_id = ".$site_id." and token != '".$token."' and uid != -1")->get('chat_user_connection');
		echo json_encode($list->result_array());
	}

	public function get_history_log(){

		$client_uid = $this->input->get('uid');
		//$client_uid = '5';
		$site_id = $_SESSION['service']->site_id;
		$list = $this->db->where(['site_id'=>$site_id,'uid'=>$client_uid])->order_by('create_time','desc')->limit(20)->get('chat_user_log');
		if($list->result()){
		   $list = $list->result_array();
		   foreach($list as $key=>$value){
		      if(stripos($value['content'],'http')===0){
		         $list[$key]['type'] = 'image';
		      }else{
		         $list[$key]['type'] = 'text';
		      }
		   }
		   echo json_encode($list);
		}else{
		   $ret = [];
		   echo json_encode($ret);
		}

	}
}
